{
 "cells": [
  {
   "cell_type": "markdown",
   "source": [
    "### 2.4.1. 导数和微分"
   ],
   "metadata": {
    "collapsed": false
   },
   "id": "3a8c3d248df35dac"
  },
  {
   "cell_type": "code",
   "outputs": [],
   "source": [
    "%matplotlib inline\n",
    "import numpy as np\n",
    "from matplotlib_inline import backend_inline\n",
    "from d2l import torch as d2l\n",
    "\n",
    "\n",
    "def f(x):\n",
    "    return 3 * x ** 2 - 4 * x"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "end_time": "2024-03-28T03:40:59.832220Z",
     "start_time": "2024-03-28T03:40:52.416357Z"
    }
   },
   "id": "d974bc4b08c915f3",
   "execution_count": 1
  },
  {
   "cell_type": "code",
   "outputs": [],
   "source": [],
   "metadata": {
    "collapsed": false
   },
   "id": "45209a3e3120ca9d"
  },
  {
   "cell_type": "code",
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "h=0.10000, numerical limit=2.30000\n",
      "h=0.01000, numerical limit=2.03000\n",
      "h=0.00100, numerical limit=2.00300\n",
      "h=0.00010, numerical limit=2.00030\n",
      "h=0.00001, numerical limit=2.00003\n"
     ]
    }
   ],
   "source": [
    "def numerical_lim(f, x, h):\n",
    "    return (f(x + h) - f(x)) / h\n",
    "\n",
    "\n",
    "h = 0.1\n",
    "for i in range(5):\n",
    "    print(f'h={h:.5f}, numerical limit={numerical_lim(f, 1, h):.5f}')\n",
    "    h *= 0.1"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "end_time": "2024-03-28T03:41:12.652206Z",
     "start_time": "2024-03-28T03:41:12.639403Z"
    }
   },
   "id": "8032e3a2e53e636b",
   "execution_count": 2
  },
  {
   "cell_type": "code",
   "outputs": [
    {
     "data": {
      "text/plain": "<Figure size 350x250 with 1 Axes>",
      "image/svg+xml": "<?xml version=\"1.0\" encoding=\"utf-8\" standalone=\"no\"?>\n<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 1.1//EN\"\n  \"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd\">\n<svg xmlns:xlink=\"http://www.w3.org/1999/xlink\" width=\"239.254688pt\" height=\"180.25pt\" viewBox=\"0 0 239.254688 180.25\" xmlns=\"http://www.w3.org/2000/svg\" version=\"1.1\">\n <metadata>\n  <rdf:RDF xmlns:dc=\"http://purl.org/dc/elements/1.1/\" xmlns:cc=\"http://creativecommons.org/ns#\" xmlns:rdf=\"http://www.w3.org/1999/02/22-rdf-syntax-ns#\">\n   <cc:Work>\n    <dc:type rdf:resource=\"http://purl.org/dc/dcmitype/StillImage\"/>\n    <dc:date>2024-03-28T11:44:33.809983</dc:date>\n    <dc:format>image/svg+xml</dc:format>\n    <dc:creator>\n     <cc:Agent>\n      <dc:title>Matplotlib v3.7.2, https://matplotlib.org/</dc:title>\n     </cc:Agent>\n    </dc:creator>\n   </cc:Work>\n  </rdf:RDF>\n </metadata>\n <defs>\n  <style type=\"text/css\">*{stroke-linejoin: round; stroke-linecap: butt}</style>\n </defs>\n <g id=\"figure_1\">\n  <g id=\"patch_1\">\n   <path d=\"M 0 180.25 \nL 239.254688 180.25 \nL 239.254688 0 \nL 0 0 \nz\n\" style=\"fill: #ffffff\"/>\n  </g>\n  <g id=\"axes_1\">\n   <g id=\"patch_2\">\n    <path d=\"M 36.754688 145.8 \nL 232.054688 145.8 \nL 232.054688 7.2 \nL 36.754688 7.2 \nz\n\" style=\"fill: #ffffff\"/>\n   </g>\n   <g id=\"matplotlib.axis_1\">\n    <g id=\"xtick_1\">\n     <g id=\"line2d_1\">\n      <path d=\"M 45.63196 145.8 \nL 45.63196 7.2 \n\" clip-path=\"url(#p7a39e19718)\" style=\"fill: none; stroke: #b0b0b0; stroke-width: 0.8; stroke-linecap: square\"/>\n     </g>\n     <g id=\"line2d_2\">\n      <defs>\n       <path id=\"mabada31265\" d=\"M 0 0 \nL 0 3.5 \n\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n      </defs>\n      <g>\n       <use xlink:href=\"#mabada31265\" x=\"45.63196\" y=\"145.8\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n      </g>\n     </g>\n     <g id=\"text_1\">\n      <!-- 0 -->\n      <g transform=\"translate(43.13196 159.675) scale(0.1 -0.1)\">\n       <defs>\n        <path id=\"SimHei-30\" d=\"M 225 2537 \nQ 250 3200 412 3587 \nQ 575 3975 875 4225 \nQ 1175 4475 1612 4475 \nQ 2050 4475 2375 4112 \nQ 2700 3750 2800 3200 \nQ 2900 2650 2862 1937 \nQ 2825 1225 2612 775 \nQ 2400 325 1975 150 \nQ 1550 -25 1125 187 \nQ 700 400 525 750 \nQ 350 1100 275 1487 \nQ 200 1875 225 2537 \nz\nM 750 2687 \nQ 675 2000 800 1462 \nQ 925 925 1212 700 \nQ 1500 475 1800 612 \nQ 2100 750 2237 1162 \nQ 2375 1575 2375 2062 \nQ 2375 2550 2337 2950 \nQ 2300 3350 2112 3675 \nQ 1925 4000 1612 4012 \nQ 1300 4025 1062 3700 \nQ 825 3375 750 2687 \nz\n\" transform=\"scale(0.015625)\"/>\n       </defs>\n       <use xlink:href=\"#SimHei-30\"/>\n      </g>\n     </g>\n    </g>\n    <g id=\"xtick_2\">\n     <g id=\"line2d_3\">\n      <path d=\"M 106.854531 145.8 \nL 106.854531 7.2 \n\" clip-path=\"url(#p7a39e19718)\" style=\"fill: none; stroke: #b0b0b0; stroke-width: 0.8; stroke-linecap: square\"/>\n     </g>\n     <g id=\"line2d_4\">\n      <g>\n       <use xlink:href=\"#mabada31265\" x=\"106.854531\" y=\"145.8\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n      </g>\n     </g>\n     <g id=\"text_2\">\n      <!-- 1 -->\n      <g transform=\"translate(104.354531 159.675) scale(0.1 -0.1)\">\n       <defs>\n        <path id=\"SimHei-31\" d=\"M 1400 3600 \nQ 1075 3275 575 2975 \nL 575 3450 \nQ 1200 3875 1600 4450 \nL 1900 4450 \nL 1900 150 \nL 1400 150 \nL 1400 3600 \nz\n\" transform=\"scale(0.015625)\"/>\n       </defs>\n       <use xlink:href=\"#SimHei-31\"/>\n      </g>\n     </g>\n    </g>\n    <g id=\"xtick_3\">\n     <g id=\"line2d_5\">\n      <path d=\"M 168.077101 145.8 \nL 168.077101 7.2 \n\" clip-path=\"url(#p7a39e19718)\" style=\"fill: none; stroke: #b0b0b0; stroke-width: 0.8; stroke-linecap: square\"/>\n     </g>\n     <g id=\"line2d_6\">\n      <g>\n       <use xlink:href=\"#mabada31265\" x=\"168.077101\" y=\"145.8\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n      </g>\n     </g>\n     <g id=\"text_3\">\n      <!-- 2 -->\n      <g transform=\"translate(165.577101 159.675) scale(0.1 -0.1)\">\n       <defs>\n        <path id=\"SimHei-32\" d=\"M 300 250 \nQ 325 625 650 925 \nQ 975 1225 1475 1862 \nQ 1975 2500 2125 2850 \nQ 2275 3200 2237 3450 \nQ 2200 3700 2000 3862 \nQ 1800 4025 1537 4000 \nQ 1275 3975 1037 3800 \nQ 800 3625 675 3275 \nL 200 3350 \nQ 400 3925 712 4187 \nQ 1025 4450 1450 4475 \nQ 1700 4500 1900 4462 \nQ 2100 4425 2312 4287 \nQ 2525 4150 2662 3875 \nQ 2800 3600 2762 3212 \nQ 2725 2825 2375 2287 \nQ 2025 1750 1025 600 \nL 2825 600 \nL 2825 150 \nL 300 150 \nL 300 250 \nz\n\" transform=\"scale(0.015625)\"/>\n       </defs>\n       <use xlink:href=\"#SimHei-32\"/>\n      </g>\n     </g>\n    </g>\n    <g id=\"xtick_4\">\n     <g id=\"line2d_7\">\n      <path d=\"M 229.299672 145.8 \nL 229.299672 7.2 \n\" clip-path=\"url(#p7a39e19718)\" style=\"fill: none; stroke: #b0b0b0; stroke-width: 0.8; stroke-linecap: square\"/>\n     </g>\n     <g id=\"line2d_8\">\n      <g>\n       <use xlink:href=\"#mabada31265\" x=\"229.299672\" y=\"145.8\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n      </g>\n     </g>\n     <g id=\"text_4\">\n      <!-- 3 -->\n      <g transform=\"translate(226.799672 159.675) scale(0.1 -0.1)\">\n       <defs>\n        <path id=\"SimHei-33\" d=\"M 250 1225 \nL 700 1300 \nQ 800 975 1025 762 \nQ 1250 550 1587 562 \nQ 1925 575 2125 837 \nQ 2325 1100 2300 1437 \nQ 2275 1775 2037 1962 \nQ 1800 2150 1275 2225 \nL 1275 2550 \nQ 1800 2600 2037 2825 \nQ 2275 3050 2250 3412 \nQ 2225 3775 1925 3937 \nQ 1625 4100 1287 3975 \nQ 950 3850 750 3275 \nL 300 3350 \nQ 450 3800 712 4100 \nQ 975 4400 1425 4450 \nQ 1875 4500 2212 4337 \nQ 2550 4175 2687 3837 \nQ 2825 3500 2725 3100 \nQ 2625 2700 2150 2400 \nQ 2500 2250 2687 1950 \nQ 2875 1650 2812 1162 \nQ 2750 675 2375 375 \nQ 2000 75 1525 87 \nQ 1050 100 700 387 \nQ 350 675 250 1225 \nz\n\" transform=\"scale(0.015625)\"/>\n       </defs>\n       <use xlink:href=\"#SimHei-33\"/>\n      </g>\n     </g>\n    </g>\n    <g id=\"text_5\">\n     <!-- x -->\n     <g transform=\"translate(131.904688 171.8) scale(0.1 -0.1)\">\n      <defs>\n       <path id=\"SimHei-78\" d=\"M 2875 125 \nL 2275 125 \nL 1550 1200 \nL 825 125 \nL 225 125 \nL 1250 1550 \nL 300 2925 \nL 900 2925 \nL 1550 1875 \nL 2200 2925 \nL 2800 2925 \nL 1850 1550 \nL 2875 125 \nz\n\" transform=\"scale(0.015625)\"/>\n      </defs>\n      <use xlink:href=\"#SimHei-78\"/>\n     </g>\n    </g>\n   </g>\n   <g id=\"matplotlib.axis_2\">\n    <g id=\"ytick_1\">\n     <g id=\"line2d_9\">\n      <path d=\"M 36.754688 116.769994 \nL 232.054688 116.769994 \n\" clip-path=\"url(#p7a39e19718)\" style=\"fill: none; stroke: #b0b0b0; stroke-width: 0.8; stroke-linecap: square\"/>\n     </g>\n     <g id=\"line2d_10\">\n      <defs>\n       <path id=\"m3cfdf5e74e\" d=\"M 0 0 \nL -3.5 0 \n\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n      </defs>\n      <g>\n       <use xlink:href=\"#m3cfdf5e74e\" x=\"36.754688\" y=\"116.769994\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n      </g>\n     </g>\n     <g id=\"text_6\">\n      <!-- 0 -->\n      <g transform=\"translate(24.754688 120.207494) scale(0.1 -0.1)\">\n       <use xlink:href=\"#SimHei-30\"/>\n      </g>\n     </g>\n    </g>\n    <g id=\"ytick_2\">\n     <g id=\"line2d_11\">\n      <path d=\"M 36.754688 78.886651 \nL 232.054688 78.886651 \n\" clip-path=\"url(#p7a39e19718)\" style=\"fill: none; stroke: #b0b0b0; stroke-width: 0.8; stroke-linecap: square\"/>\n     </g>\n     <g id=\"line2d_12\">\n      <g>\n       <use xlink:href=\"#m3cfdf5e74e\" x=\"36.754688\" y=\"78.886651\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n      </g>\n     </g>\n     <g id=\"text_7\">\n      <!-- 5 -->\n      <g transform=\"translate(24.754688 82.324151) scale(0.1 -0.1)\">\n       <defs>\n        <path id=\"SimHei-35\" d=\"M 550 1325 \nQ 725 650 1150 575 \nQ 1575 500 1837 662 \nQ 2100 825 2212 1087 \nQ 2325 1350 2312 1675 \nQ 2300 2000 2137 2225 \nQ 1975 2450 1725 2525 \nQ 1475 2600 1162 2525 \nQ 850 2450 650 2175 \nL 225 2225 \nQ 275 2375 700 4375 \nL 2675 4375 \nL 2675 3925 \nL 1075 3925 \nQ 950 3250 825 2850 \nQ 1200 3025 1525 3012 \nQ 1850 3000 2150 2862 \nQ 2450 2725 2587 2487 \nQ 2725 2250 2787 2012 \nQ 2850 1775 2837 1500 \nQ 2825 1225 2725 937 \nQ 2625 650 2425 462 \nQ 2225 275 1937 162 \nQ 1650 50 1275 75 \nQ 900 100 562 350 \nQ 225 600 100 1200 \nL 550 1325 \nz\n\" transform=\"scale(0.015625)\"/>\n       </defs>\n       <use xlink:href=\"#SimHei-35\"/>\n      </g>\n     </g>\n    </g>\n    <g id=\"ytick_3\">\n     <g id=\"line2d_13\">\n      <path d=\"M 36.754688 41.003307 \nL 232.054688 41.003307 \n\" clip-path=\"url(#p7a39e19718)\" style=\"fill: none; stroke: #b0b0b0; stroke-width: 0.8; stroke-linecap: square\"/>\n     </g>\n     <g id=\"line2d_14\">\n      <g>\n       <use xlink:href=\"#m3cfdf5e74e\" x=\"36.754688\" y=\"41.003307\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n      </g>\n     </g>\n     <g id=\"text_8\">\n      <!-- 10 -->\n      <g transform=\"translate(19.754688 44.440807) scale(0.1 -0.1)\">\n       <use xlink:href=\"#SimHei-31\"/>\n       <use xlink:href=\"#SimHei-30\" x=\"50\"/>\n      </g>\n     </g>\n    </g>\n    <g id=\"text_9\">\n     <!-- f(x) -->\n     <g transform=\"translate(14.504688 86.5) rotate(-90) scale(0.1 -0.1)\">\n      <defs>\n       <path id=\"SimHei-66\" d=\"M 2850 3825 \nQ 2725 3900 2550 3950 \nQ 2375 4000 2100 4000 \nQ 1825 4000 1725 3862 \nQ 1625 3725 1625 3525 \nL 1625 2925 \nL 2650 2925 \nL 2650 2525 \nL 1625 2525 \nL 1625 125 \nL 1125 125 \nL 1125 2525 \nL 275 2525 \nL 275 2925 \nL 1125 2925 \nL 1125 3500 \nQ 1125 3950 1400 4200 \nQ 1675 4450 2125 4450 \nQ 2400 4450 2562 4412 \nQ 2725 4375 2850 4325 \nL 2850 3825 \nz\n\" transform=\"scale(0.015625)\"/>\n       <path id=\"SimHei-28\" d=\"M 2975 -200 \nL 2700 -475 \nQ 2075 125 1762 775 \nQ 1450 1425 1450 2250 \nQ 1450 3075 1762 3725 \nQ 2075 4375 2700 5000 \nL 2975 4725 \nQ 2400 4175 2112 3587 \nQ 1825 3000 1825 2250 \nQ 1825 1500 2112 912 \nQ 2400 325 2975 -200 \nz\n\" transform=\"scale(0.015625)\"/>\n       <path id=\"SimHei-29\" d=\"M 1675 2250 \nQ 1675 1425 1362 775 \nQ 1050 125 425 -475 \nL 150 -200 \nQ 725 325 1012 912 \nQ 1300 1500 1300 2250 \nQ 1300 3000 1012 3587 \nQ 725 4175 150 4725 \nL 425 5000 \nQ 1050 4375 1362 3725 \nQ 1675 3075 1675 2250 \nz\n\" transform=\"scale(0.015625)\"/>\n      </defs>\n      <use xlink:href=\"#SimHei-66\"/>\n      <use xlink:href=\"#SimHei-28\" x=\"50\"/>\n      <use xlink:href=\"#SimHei-78\" x=\"100\"/>\n      <use xlink:href=\"#SimHei-29\" x=\"150\"/>\n     </g>\n    </g>\n   </g>\n   <g id=\"line2d_15\">\n    <path d=\"M 45.63196 116.769994 \nL 51.754217 119.573361 \nL 57.876474 121.922129 \nL 63.998731 123.816296 \nL 70.120988 125.255863 \nL 76.243245 126.24083 \nL 82.365503 126.771197 \nL 88.48776 126.846963 \nL 94.610017 126.46813 \nL 100.732274 125.634696 \nL 106.854531 124.346663 \nL 112.976788 122.604029 \nL 119.099045 120.406795 \nL 125.221302 117.754961 \nL 131.343559 114.648527 \nL 137.465816 111.087492 \nL 143.588073 107.071858 \nL 149.71033 102.601624 \nL 155.832587 97.676789 \nL 161.954844 92.297354 \nL 168.077101 86.463319 \nL 174.199358 80.174684 \nL 180.321615 73.431449 \nL 186.443872 66.233614 \nL 192.56613 58.581179 \nL 198.688387 50.474143 \nL 204.810644 41.912508 \nL 210.932901 32.896272 \nL 217.055158 23.425436 \nL 223.177415 13.5 \n\" clip-path=\"url(#p7a39e19718)\" style=\"fill: none; stroke: #1f77b4; stroke-width: 1.5; stroke-linecap: square\"/>\n   </g>\n   <g id=\"line2d_16\">\n    <path d=\"M 45.63196 139.5 \nL 51.754217 137.984666 \nL 57.876474 136.469333 \nL 63.998731 134.953999 \nL 70.120988 133.438665 \nL 76.243245 131.923331 \nL 82.365503 130.407998 \nL 88.48776 128.892664 \nL 94.610017 127.37733 \nL 100.732274 125.861996 \nL 106.854531 124.346663 \nL 112.976788 122.831329 \nL 119.099045 121.315995 \nL 125.221302 119.800661 \nL 131.343559 118.285328 \nL 137.465816 116.769994 \nL 143.588073 115.25466 \nL 149.71033 113.739327 \nL 155.832587 112.223993 \nL 161.954844 110.708659 \nL 168.077101 109.193325 \nL 174.199358 107.677992 \nL 180.321615 106.162658 \nL 186.443872 104.647324 \nL 192.56613 103.13199 \nL 198.688387 101.616657 \nL 204.810644 100.101323 \nL 210.932901 98.585989 \nL 217.055158 97.070655 \nL 223.177415 95.555322 \n\" clip-path=\"url(#p7a39e19718)\" style=\"fill: none; stroke-dasharray: 5.55,2.4; stroke-dashoffset: 0; stroke: #bf00bf; stroke-width: 1.5\"/>\n   </g>\n   <g id=\"patch_3\">\n    <path d=\"M 36.754688 145.8 \nL 36.754688 7.2 \n\" style=\"fill: none; stroke: #000000; stroke-width: 0.8; stroke-linejoin: miter; stroke-linecap: square\"/>\n   </g>\n   <g id=\"patch_4\">\n    <path d=\"M 232.054688 145.8 \nL 232.054688 7.2 \n\" style=\"fill: none; stroke: #000000; stroke-width: 0.8; stroke-linejoin: miter; stroke-linecap: square\"/>\n   </g>\n   <g id=\"patch_5\">\n    <path d=\"M 36.754688 145.8 \nL 232.054688 145.8 \n\" style=\"fill: none; stroke: #000000; stroke-width: 0.8; stroke-linejoin: miter; stroke-linecap: square\"/>\n   </g>\n   <g id=\"patch_6\">\n    <path d=\"M 36.754688 7.2 \nL 232.054688 7.2 \n\" style=\"fill: none; stroke: #000000; stroke-width: 0.8; stroke-linejoin: miter; stroke-linecap: square\"/>\n   </g>\n   <g id=\"legend_1\">\n    <g id=\"patch_7\">\n     <path d=\"M 43.754688 42.817187 \nL 165.754687 42.817187 \nQ 167.754687 42.817187 167.754687 40.817187 \nL 167.754687 14.2 \nQ 167.754687 12.2 165.754687 12.2 \nL 43.754688 12.2 \nQ 41.754688 12.2 41.754688 14.2 \nL 41.754688 40.817187 \nQ 41.754688 42.817187 43.754688 42.817187 \nz\n\" style=\"fill: #ffffff; opacity: 0.8; stroke: #cccccc; stroke-linejoin: miter\"/>\n    </g>\n    <g id=\"line2d_17\">\n     <path d=\"M 45.754688 20.004687 \nL 55.754688 20.004687 \nL 65.754688 20.004687 \n\" style=\"fill: none; stroke: #1f77b4; stroke-width: 1.5; stroke-linecap: square\"/>\n    </g>\n    <g id=\"text_10\">\n     <!-- f(x) -->\n     <g transform=\"translate(73.754688 23.504687) scale(0.1 -0.1)\">\n      <use xlink:href=\"#SimHei-66\"/>\n      <use xlink:href=\"#SimHei-28\" x=\"50\"/>\n      <use xlink:href=\"#SimHei-78\" x=\"100\"/>\n      <use xlink:href=\"#SimHei-29\" x=\"150\"/>\n     </g>\n    </g>\n    <g id=\"line2d_18\">\n     <path d=\"M 45.754688 34.067187 \nL 55.754688 34.067187 \nL 65.754688 34.067187 \n\" style=\"fill: none; stroke-dasharray: 5.55,2.4; stroke-dashoffset: 0; stroke: #bf00bf; stroke-width: 1.5\"/>\n    </g>\n    <g id=\"text_11\">\n     <!-- Tangent line (x=1) -->\n     <g transform=\"translate(73.754688 37.567187) scale(0.1 -0.1)\">\n      <defs>\n       <path id=\"SimHei-54\" d=\"M 2850 3925 \nL 1850 3925 \nL 1850 125 \nL 1275 125 \nL 1275 3925 \nL 275 3925 \nL 275 4400 \nL 2850 4400 \nL 2850 3925 \nz\n\" transform=\"scale(0.015625)\"/>\n       <path id=\"SimHei-61\" d=\"M 2875 125 \nL 2275 125 \nQ 2225 175 2200 262 \nQ 2175 350 2175 475 \nQ 2000 275 1750 175 \nQ 1500 75 1225 75 \nQ 825 75 550 275 \nQ 275 475 275 850 \nQ 275 1225 525 1450 \nQ 775 1675 1300 1750 \nQ 1650 1800 1912 1875 \nQ 2175 1950 2175 2075 \nQ 2175 2225 2062 2375 \nQ 1950 2525 1575 2525 \nQ 1275 2525 1137 2412 \nQ 1000 2300 950 2100 \nL 400 2100 \nQ 450 2500 762 2737 \nQ 1075 2975 1575 2975 \nQ 2125 2975 2400 2725 \nQ 2675 2475 2675 2025 \nL 2675 650 \nQ 2675 500 2725 375 \nQ 2775 250 2875 125 \nz\nM 2175 1050 \nL 2175 1550 \nQ 2025 1500 1887 1462 \nQ 1750 1425 1425 1375 \nQ 1050 1325 937 1200 \nQ 825 1075 825 900 \nQ 825 750 937 637 \nQ 1050 525 1275 525 \nQ 1500 525 1762 650 \nQ 2025 775 2175 1050 \nz\n\" transform=\"scale(0.015625)\"/>\n       <path id=\"SimHei-6e\" d=\"M 2800 125 \nL 2300 125 \nL 2300 1925 \nQ 2300 2225 2150 2400 \nQ 2000 2575 1750 2575 \nQ 1425 2575 1137 2237 \nQ 850 1900 850 1400 \nL 850 125 \nL 350 125 \nL 350 2925 \nL 850 2925 \nL 850 2400 \nQ 1050 2675 1287 2825 \nQ 1525 2975 1900 2975 \nQ 2350 2975 2575 2725 \nQ 2800 2475 2800 2100 \nL 2800 125 \nz\n\" transform=\"scale(0.015625)\"/>\n       <path id=\"SimHei-67\" d=\"M 2975 2500 \nQ 2800 2550 2637 2562 \nQ 2475 2575 2300 2525 \nQ 2375 2450 2425 2337 \nQ 2475 2225 2475 2000 \nQ 2475 1575 2187 1300 \nQ 1900 1025 1475 1025 \nQ 1375 1025 1212 1062 \nQ 1050 1100 950 1150 \nQ 875 1100 850 1050 \nQ 825 1000 825 925 \nQ 825 800 1000 737 \nQ 1175 675 1625 675 \nQ 2350 675 2612 475 \nQ 2875 275 2875 -25 \nQ 2875 -425 2487 -612 \nQ 2100 -800 1575 -800 \nQ 900 -800 575 -625 \nQ 250 -450 250 -150 \nQ 250 0 375 150 \nQ 500 300 700 400 \nQ 550 475 462 587 \nQ 375 700 375 875 \nQ 375 1025 487 1137 \nQ 600 1250 750 1325 \nQ 625 1450 550 1625 \nQ 475 1800 475 2000 \nQ 475 2425 762 2700 \nQ 1050 2975 1475 2975 \nQ 1700 2975 1862 2912 \nQ 2025 2850 2150 2725 \nQ 2350 2875 2550 2937 \nQ 2750 3000 2975 2975 \nL 2975 2500 \nz\nM 1975 2000 \nQ 1975 2250 1850 2400 \nQ 1725 2550 1475 2550 \nQ 1225 2550 1100 2400 \nQ 975 2250 975 2000 \nQ 975 1750 1100 1600 \nQ 1225 1450 1475 1450 \nQ 1725 1450 1850 1600 \nQ 1975 1750 1975 2000 \nz\nM 2400 -75 \nQ 2400 25 2287 125 \nQ 2175 225 1725 225 \nQ 1625 225 1450 237 \nQ 1275 250 1050 275 \nQ 850 200 775 100 \nQ 700 0 700 -100 \nQ 700 -250 900 -350 \nQ 1100 -450 1600 -450 \nQ 2025 -450 2212 -337 \nQ 2400 -225 2400 -75 \nz\n\" transform=\"scale(0.015625)\"/>\n       <path id=\"SimHei-65\" d=\"M 2850 1075 \nQ 2800 625 2450 350 \nQ 2100 75 1625 75 \nQ 1025 75 637 462 \nQ 250 850 250 1525 \nQ 250 2200 637 2587 \nQ 1025 2975 1625 2975 \nQ 2150 2975 2487 2637 \nQ 2825 2300 2825 1525 \nL 800 1525 \nQ 800 975 1037 750 \nQ 1275 525 1625 525 \nQ 1900 525 2075 662 \nQ 2250 800 2300 1075 \nL 2850 1075 \nz\nM 2250 1925 \nQ 2200 2275 2025 2412 \nQ 1850 2550 1575 2550 \nQ 1325 2550 1125 2412 \nQ 925 2275 825 1925 \nL 2250 1925 \nz\n\" transform=\"scale(0.015625)\"/>\n       <path id=\"SimHei-74\" d=\"M 2750 200 \nQ 2625 150 2462 112 \nQ 2300 75 2025 75 \nQ 1575 75 1300 325 \nQ 1025 575 1025 1025 \nL 1025 2525 \nL 175 2525 \nL 175 2925 \nL 1025 2925 \nL 1025 3900 \nL 1525 3900 \nL 1525 2925 \nL 2550 2925 \nL 2550 2525 \nL 1525 2525 \nL 1525 1000 \nQ 1525 800 1625 662 \nQ 1725 525 2000 525 \nQ 2275 525 2450 575 \nQ 2625 625 2750 700 \nL 2750 200 \nz\n\" transform=\"scale(0.015625)\"/>\n       <path id=\"SimHei-20\" transform=\"scale(0.015625)\"/>\n       <path id=\"SimHei-6c\" d=\"M 1825 125 \nL 1325 125 \nL 1325 4400 \nL 1825 4400 \nL 1825 125 \nz\n\" transform=\"scale(0.015625)\"/>\n       <path id=\"SimHei-69\" d=\"M 1800 3725 \nL 1300 3725 \nL 1300 4375 \nL 1800 4375 \nL 1800 3725 \nz\nM 1800 125 \nL 1300 125 \nL 1300 2925 \nL 1800 2925 \nL 1800 125 \nz\n\" transform=\"scale(0.015625)\"/>\n       <path id=\"SimHei-3d\" d=\"M 2975 2900 \nL 125 2900 \nL 125 3300 \nL 2975 3300 \nL 2975 2900 \nz\nM 2975 1375 \nL 125 1375 \nL 125 1775 \nL 2975 1775 \nL 2975 1375 \nz\n\" transform=\"scale(0.015625)\"/>\n      </defs>\n      <use xlink:href=\"#SimHei-54\"/>\n      <use xlink:href=\"#SimHei-61\" x=\"50\"/>\n      <use xlink:href=\"#SimHei-6e\" x=\"100\"/>\n      <use xlink:href=\"#SimHei-67\" x=\"150\"/>\n      <use xlink:href=\"#SimHei-65\" x=\"200\"/>\n      <use xlink:href=\"#SimHei-6e\" x=\"250\"/>\n      <use xlink:href=\"#SimHei-74\" x=\"300\"/>\n      <use xlink:href=\"#SimHei-20\" x=\"350\"/>\n      <use xlink:href=\"#SimHei-6c\" x=\"400\"/>\n      <use xlink:href=\"#SimHei-69\" x=\"450\"/>\n      <use xlink:href=\"#SimHei-6e\" x=\"500\"/>\n      <use xlink:href=\"#SimHei-65\" x=\"550\"/>\n      <use xlink:href=\"#SimHei-20\" x=\"600\"/>\n      <use xlink:href=\"#SimHei-28\" x=\"650\"/>\n      <use xlink:href=\"#SimHei-78\" x=\"700\"/>\n      <use xlink:href=\"#SimHei-3d\" x=\"750\"/>\n      <use xlink:href=\"#SimHei-31\" x=\"800\"/>\n      <use xlink:href=\"#SimHei-29\" x=\"850\"/>\n     </g>\n    </g>\n   </g>\n  </g>\n </g>\n <defs>\n  <clipPath id=\"p7a39e19718\">\n   <rect x=\"36.754688\" y=\"7.2\" width=\"195.3\" height=\"138.6\"/>\n  </clipPath>\n </defs>\n</svg>\n"
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "x = np.arange(0, 3, 0.1)\n",
    "d2l.plot(x, [f(x), 2 * x - 3], 'x', 'f(x)', legend=['f(x)', 'Tangent line (x=1)'])"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "end_time": "2024-03-28T03:44:33.858426Z",
     "start_time": "2024-03-28T03:44:33.593642Z"
    }
   },
   "id": "f259509e5b0d8fc1",
   "execution_count": 3
  },
  {
   "cell_type": "markdown",
   "source": [
    "### 2.4.2. 偏导数"
   ],
   "metadata": {
    "collapsed": false
   },
   "id": "36edb6fc04787bdc"
  },
  {
   "cell_type": "markdown",
   "source": [
    "### 2.4.3. 梯度\n",
    "函数$f(\\bold{x})$相对于$\\bold{x}$是一个包含$n$个偏导数的向量：\n",
    "$$ \n",
    "\\nabla_xf(x)=[\\frac{\\partial f(x)}{\\partial x_1},\\frac{\\partial f(x)}{\\partial x_2},\\cdots,\\frac{\\partial f(x)}{\\partial x_n}]^\\text{T}\n",
    "$$\n",
    "\n",
    "> 注意是按分子布局还是按分母布局\n",
    "\n",
    "参考链接：https://www.bilibili.com/video/BV1av4y1b7MM"
   ],
   "metadata": {
    "collapsed": false
   },
   "id": "cdd9c95fa480ce84"
  },
  {
   "cell_type": "code",
   "outputs": [],
   "source": [],
   "metadata": {
    "collapsed": false
   },
   "id": "1d8b21bc523f8f9d"
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 2
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython2",
   "version": "2.7.6"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
